home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- log.c
-
- This module handles logging.
-
- Copyright © 1994-1995, Northwestern University.
-
- ----------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <string.h>
-
- #include "glob.h"
- #include "log.h"
- #include "dialog.h"
- #include "strutil.h"
- #include "fileutil.h"
- #include "resutil.h"
- #include "ic.h"
-
-
-
- static short gRefNum = 0;
-
-
-
- /*----------------------------------------------------------------------------
- PutString
-
- Write a string to the log file.
-
- Entry: str = string to write.
- ----------------------------------------------------------------------------*/
-
- static void PutString (char *str)
- {
- unsigned long secs;
- DateTimeRec d;
- char line[1024];
- long len;
-
- GetDateTime(&secs);
- Secs2Date(secs, &d);
- sprintf(line, "%.2d/%.2d/%.2d %.2d:%.2d:%.2d %s\n",
- d.month, d.day, d.year, d.hour, d.minute, d.second, str);
- len = strlen(line);
- MyFSWriteNoCache(gRefNum, &len, line, nil);
- }
-
-
-
- /*----------------------------------------------------------------------------
- OpenLogFile
-
- Open the log file.
- ----------------------------------------------------------------------------*/
-
- void OpenLogFile (void)
- {
- FCBPBRec pBlock;
- FSSpec logFile;
- OSErr err = noErr;
- Str255 versStr, fileName;
- CStr255 str, fmt;
- Boolean empty;
-
- MyICReadSharedPrefs(kICeditorHelper);
-
- if (gRefNum != 0) return;
- pBlock.ioNamePtr = nil;
- pBlock.ioVRefNum = 0;
- pBlock.ioRefNum = LMGetCurApRefNum();
- pBlock.ioFCBIndx = 0;
- err = PBGetFCBInfo(&pBlock, false);
- if (err != noErr) goto exit;
- GetPString(kStrLogFileName, fileName);
- err = FSMakeFSSpec(pBlock.ioFCBVRefNum, pBlock.ioFCBParID,
- fileName, &logFile);
- if (err != noErr && err != fnfErr) goto exit;
-
- err = OpenDataForkWriteCreateIfMissing(&logFile, gPrefs.savedArtCreator, 'TEXT',
- smSystemScript, false, &gRefNum, &empty);
- if (err != noErr) goto exit;
-
- PutString("");
- PutString("------------------------------------------------------------------------------");
- PutString("");
- GetCString(kStrLogOpenMsg, str);
- PutString(str);
- err = GetVersionString(versStr);
- if (err != noErr) goto exit;
- GetCString(kStrNewsWatcherVersion, fmt);
- p2cstr(versStr);
- sprintf(str, fmt, versStr);
- PutString(str);
- GetCString(kStrLogLegend, str);
- PutString(str);
- PutString("");
- return;
-
- exit:
-
- if (gRefNum != 0) MyFSClose(gRefNum, nil);
- gRefNum = 0;
- ErrorMessageNumber(kStrLogCantOpen);
- }
-
-
-
- /*----------------------------------------------------------------------------
- CloseLogFile
-
- Close the log file.
- ----------------------------------------------------------------------------*/
-
- void CloseLogFile (void)
- {
- CStr255 str;
-
- if (gRefNum == 0) return;
- PutString("");
- GetCString(kStrLogClosed, str);
- PutString(str);
- MyFSClose(gRefNum, nil);
- gRefNum = 0;
- }
-
-
-
- /*----------------------------------------------------------------------------
- Log
-
- Log a server command or response.
-
- Entry: command =
- 'C' if command.
- 'R' if response.
- ' ' if open/close.
- serverAddr = IP address of server.
- serverPort = server port number.
- localPort = local port number.
- str = command or response string or open/close message.
- ----------------------------------------------------------------------------*/
-
- void Log (char logEntryType, unsigned long serverAddr, unsigned short serverPort,
- unsigned short localPort, char *str)
- {
- char *filteredStr;
- char line[512];
-
- if (gRefNum == 0) return;
- if (logEntryType == 'C' && MyStrNEqual(str, "PASS", 4)) {
- filteredStr = "PASS *******";
- } else if (logEntryType == 'C' && MyStrNEqual(str, "AUTHINFO PASS", 13)) {
- filteredStr = "AUTHINFO PASS *******";
- } else {
- filteredStr = str;
- }
- sprintf(line, "%c %lu.%lu.%lu.%lu %u %u %s",
- logEntryType,
- (serverAddr >> 24) & 0xff, (serverAddr >> 16) & 0xff,
- (serverAddr >> 8) & 0xff, serverAddr & 0xff,
- serverPort, localPort,
- filteredStr);
- PutString(line);
- }
-